package com.com.typhoon.dao;

import com.com.typhoon.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/23 下午2:29
 * @description
 * @modified by
 * @since V2.0.0
 */
@Repository
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<User> findAllUsers() {
        return this.jdbcTemplate.query("select * from User", BeanPropertyRowMapper.newInstance(User.class));
    }

    public User getByPK(Long id) {
        List<User> list = this.jdbcTemplate.query("select * from User where id = ? limit 1  ",  BeanPropertyRowMapper.newInstance(User.class),id);
        if(null == list || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }


}
